package com.then.basic.socket.core;


import com.then.basic.socket.ThreadUtil;

/**
 *
 * Created by longyi on 16/6/14.
 */
public class RoomReqAsync {
    private int roomID;
    private int roomPath;

    public RoomReqAsync(int roomID, int roomPath) {
        this.roomID = roomID;
        this.roomPath = roomPath;
    }

    public void enterRoom(int connectionType, int sitType,int clubId) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.EnterRoom;
        task.wparam = sitType;
        task.lparam = connectionType;
        task.zparam=clubId;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void startGame() {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.StartGame;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void pauseGame(boolean bPause) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.Pause;
        task.wparam = bPause ? 1 : 0;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void addTime(int time, int chips, int playerSeatPosition, boolean insuranceMode) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = insuranceMode ? TcpSendThread.AddTimeOfInsurance : TcpSendThread.AddTime;
        task.wparam = time;
        task.lparam = chips;
        task.zparam = playerSeatPosition;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void sendUserAction(int action, int chips) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = action;
        task.roomid = roomID;
        task.roompath = roomPath;
        task.wparam = chips;
        TcpSendThread.getInstance().startTask(task);
    }

    public void showDown(int pokernum,int show) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.roomid = roomID;
        task.roompath = roomPath;
        task.wparam = pokernum;
        task.lparam=show;
        task.action = TcpSendThread.Showdown;
        TcpSendThread.getInstance().startTask(task);
    }

    public void permitUserTakeIn(int uid, int allow_chips) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.PermitUserTakeIn;
        task.wparam = uid;
        task.lparam = allow_chips;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void enableTakeIn(boolean bEnable) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.EnableTakeInControl;
        task.bparam = bEnable;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void changeTakeInRate(int minTakeInRate, int maxTakeInRate) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.ChangeTakeInRange;
        task.wparam = minTakeInRate;
        task.lparam = maxTakeInRate;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void addChips(int seatIndex, int addChips, boolean fillToLastLeave, String longitude, String latitude) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.AddChips;
        task.wparam = seatIndex;
        task.lparam = addChips;
        task.zparam = fillToLastLeave ? 1 : 0;
        task.eparam = longitude; // 经度
        task.xparam = latitude;  // 纬度
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public static final int ACTION_SIT_DOWN = 1; // 坐下
    public static final int ACTION_STAND_UP = 2; // 站起
    public static final int ACTION_LEAVE = 3;    // 离开

    public void seatAction(int seatIndex, int seatAction, String longitude, String latitude) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.Seat;
        task.wparam = seatIndex;
        task.lparam = seatAction;
        task.eparam = longitude; // 经度
        task.xparam = latitude;  // 纬度
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void sitDown(int seatIndex, String longitude, String latitude) {
        seatAction(seatIndex, ACTION_SIT_DOWN, longitude, latitude);
    }

    public void standUp(int seatIndex) {
        seatAction(seatIndex, ACTION_STAND_UP, "0", "0");
    }

    public void leaveRoom(int seatIndex) {
        seatAction(seatIndex, ACTION_LEAVE, "0", "0");
    }

    // mtt消息系列
    public void mttEnterRoom(int realRoomId) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.MttEnterRoom;
        task.roomid = roomID;
        task.roompath = roomPath;
        task.realRoomId=realRoomId;
        TcpSendThread.getInstance().startTask(task);
    }

    public void mttGetAllPeople() {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.MttGetAllPeople;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void requestNextCard(final byte publicCardsCount) {
        ThreadUtil.async(new Runnable() {
            @Override
            public void run() {
                PokerReq.reqNextPublicCard(roomID, roomPath, publicCardsCount);
            }
        });
    }

    // sng消息系列
    public void sngEnterRoom() {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.SngEnterRoom;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void sngAddTime(int time, int chips, int playerSeatPosition) {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.SngAddTime;
        task.wparam = time;
        task.lparam = chips;
        task.zparam = playerSeatPosition;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    public void requestKeepSeat(final int minute,final  int versionCode) {
        ThreadUtil.async(new Runnable() {
            @Override
            public void run() {
                PokerReq.reqKeepSeat(roomID, roomPath, (byte) 1,minute,versionCode);
            }
        });
    }

    public void requestOtherRoomKeepSeatStatus(final  int versionCode) {
        ThreadUtil.async(new Runnable() {
            @Override
            public void run() {
                PokerReq.reqKeepSeat(roomID, roomPath, (byte) 2,0,versionCode);
            }
        });
    }

    public void requestDelayRoomTime(final int minutes) {
        ThreadUtil.async(new Runnable() {
            @Override
            public void run() {
                PokerReq.reqDelayRoomTime(roomID, roomPath, minutes);
            }
        });
    }

    // omaha进入房间消息
    public void omahaEnterRoom() {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.OmahaEnterRoom;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }

    // 大菠萝进入房间消息
    public void pineappleEnterRoom() {
        TcpSendThread.ActionTask task = TcpSendThread.getInstance().getActionTask();
        task.action = TcpSendThread.PineappleEnterRoom;
        task.roomid = roomID;
        task.roompath = roomPath;
        TcpSendThread.getInstance().startTask(task);
    }
}
